mod metric;
use metric::{register_metrics,metric_handler,ACTION};
use prometheus::{self};
use axum::{
  routing::{get},
  Router,
  serve,
};
// mod metrics2;
// use metrics2::{Metrics};

// use crate::metrics2::metrics_handler2;
#[tokio::main]
async fn main(){
  register_metrics(prometheus::default_registry());
  ACTION.inc();
  let app = Router::new().route("/metrics", get(
    metric_handler
  ));

  // let mut metircs=Metrics::new();
  // metircs.inc_counter(&"ab", &"cd");
  // metircs.set_guage(&"ab", &"cd");
  // let app = Router::new().route("/metrics",get(
  //   {
  //     let  base_metircs=metircs.clone();
  //   move || metrics_handler2(base_metircs)}));


  let addr = tokio::net::TcpListener::bind("0.0.0.0:3001").await.unwrap();
  println!("Listening on {}", addr.local_addr().unwrap());
  serve(addr, app.into_make_service()).await.unwrap();




}
// fn main() {
//     register_metrics(prometheus::default_registry());
//     let mut labels = HashMap::new();
//     labels.insert("mykey".to_string(), "myvalue".to_string());
//      let custom_registry = Registry::new_custom(Some("myprefix".to_string()), Some(labels)).unwrap();
//     custom_metrics(&custom_registry);
//    //打印default registry metrics
//    let mut buffer:Vec<u8> = Vec::new();
//    let encoder = prometheus::TextEncoder::new();
//    encoder.encode(&prometheus::gather(), &mut buffer).unwrap();
//    println!("## Default registry");
//    println!("{}", String::from_utf8(buffer.clone()).unwrap());
//    //打印custom registry metrics
//   let mut buffer:Vec<u8> = Vec::new();
//   let encoder = prometheus::TextEncoder::new();
//   encoder.encode(&custom_registry.gather(), &mut buffer).unwrap();
//   println!("## Custom registry");
//   println!("{}", String::from_utf8(buffer.clone()).unwrap());
// }


